const path = require('path')
const isProduction = process.env.NODE_ENV === 'production'
let externals = {}
if (isProduction) {
  externals = {
    vue: 'Vue',
    'element-ui': 'ELEMENT',
    xlsx: 'XLSX',
    echarts: 'echarts',
    // axios: 'axios',
    dayjs: 'dayjs',
    'vue-quill-editor': 'VueQuillEditor'
  }
}
module.exports = {
  publicPath: './',
  devServer: {
    open: true,
    proxy: {
      '/api': {
        target: 'http://hmmm-api.itheima.net'
        // changeOrigin: true,
        // pathRewrite: {
        //   '^/api': 'api'
        // }
      }
    }
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    externals: externals
  },
  lintOnSave: false,
  chainWebpack: (config) => {
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .test(/.svg$/)
      .include.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    const fileRule = config.module.rule('file')
    fileRule.uses.clear()
    fileRule
      .test(/.svg$/)
      .exclude.add(path.resolve(__dirname, './src/icons/svg'))
      .end()
      .use('file-loader')
      .loader('file-loader')
  }
}
